(function () {
    type = utils.getParams(1);

    var template = {
        kaifu: `<li class="os-list-item">
                    <div>
                        <div class="os-item-time ellipse">
                            <span class="iconfont icon-shijian"></span>{% data.push_time %}
                        </div>
                        <div class="os-item-game">
                            <a href="/game/detail/{% data.game_id %}" target="_blank">
                                <img data-original="{% data.game_img %}">
                            </a>
                            <h2 class="ellipse">
                                <a href="/game/detail/{% data.game_id %}" target="_blank">{% data.game_name %}</a>
                            </h2>
                            {% if( data.is_android ){ %}
                                <div class="iconfont icon-anzhuo"></div>
                            {% } %}
                            {% if( data.is_ios ){ %}
                                <div class="iconfont icon-iOS"></div>
                            {% } %}
                        </div>
                    </div>
                    <div class="os-item-right">
                    {% if( data.type ){ %}
                        <div class="os-item-server ellipse">{% data.type %}</div>
                    {% }else{ %}
                        <div class="os-item-server ellipse">{% data.name %}</div>
                    {% } %}
                       
                        <a href="/game/detail/{% data.game_id %}" class="os-item-btn">下载</a>
                    </div>
                </li>`,
        libao: `<li class="common-game-item">
                    <a class="common-game-avatar"  href="{% data.id %}" target="_blank">
                        <img data-original="{% data.game_img %}">
                    </a>
                    <div class="common-game-detail">
                      <div class="common-game-info">
                        <div class="common-game-name">
                          <a class="ellipse" href="{% data.id %}" target="_blank">{% data.name %}</a>
                            {% if( data.is_android ){ %}
                                <span class="iconfont icon-anzhuo"></span>
                            {% } %}
                            {% if( data.is_ios ){ %}
                                <span class="iconfont icon-iOS"></span>
                            {% } %}
                        </div>
                        <div class="common-game-intro ellipse" style="color: #666"> 所属游戏：<span style="color: #000;">{% data.game_name %}</span></div>
                        <div class="common-game-additional">
                            ${(function () {
                                    if(type === 'libao'){
                                        return `<div class="progress-wrapper">
                                                    <div class="progress-bar">
                                                        <div class="progress-rate" style="width:{% (data.last_num / data.all_num * 100).toFixed(2)%}%"></div>
                                                    </div>
                                                    <span class="progress-num">{% (data.last_num / data.all_num * 100).toFixed(2) %}%</span>
                                                </div>`
                                    }else if(type === 'coupon'){
                                        return `<div style="margin-right: 20px">剩余<span style="color: #FF4545;">{% data.last_num %}</span>个</div>
                                                <div style="color: #999;">自激活后{% data.valid_day %}日内有效</div>`
                                    }
                                })()
                              }
                       </div>
                      </div>
                      <a class="common-game-btn"  href="{% data.id %}" target="_blank">领取</a>
                    </div>
                </li>`
    };

    function main() {
        var curTmpl = '',
            list;

        switch(type)
        {
            case 'libao': {
                curTmpl = template.libao;
                break;
            }
            case 'coupon': {
                curTmpl = template.libao;
                break;
            }
            case 'kaifu': {
                curTmpl = template.kaifu;
                break;
            }
            case 'fuli' : {
                curTmpl = template.kaifu;
                break;
            }
        }
        if( type === 'kaifu' || type === 'fuli' ){
            $('#slideTabList').slideTab({
                nodes: {
                    slideTab : '#slideTabList',
                    tabThumb : '#panelTitleTabs',
                    thumbItems : '.panel-title-tab',
                    panelContainer : '.tab-container',
                    panelWrapper : '.tab-panel-wrapper',
                    panelItems : '.tab-panel'
                },
                activeClass: 'tab-active',
                initTabFn: function ( _self ) {
                    //创建点击加载更多功能
                    var tabBtns = _self.Nodes.$thumbItems;
                    $.each( tabBtns, function ( index, item ) {
                        var id = index + 1;
                        var list = new LoadData({
                            btn: '#getMoreBtn' + index,
                            lists: $('.open-server-list')[index],
                            listType: 'info',
                            url: '/kaifu/ajax_kf_kc/' + id,
                            page: 2,
                            template: curTmpl,
                            method: 'append',
                            loadingAnim: true,
                            loadingAnimDom: '.loading-container',
                            handleFn: {
                                'push_time': utils.getLocalTime.bind(utils),
                                'type': function ( key ) {
                                    var arr = ['删档内测','删档公测','不删档内测','内测','公测'];
                                    return arr[key - 1];
                                }
                            },
                            afterRender: function () {
                                $("img").lazyload({
                                    effect: "fadeIn",
                                    effectspeed: 1500
                                });
                            }
                        });
                    });

                }
            });
        }else{
            //初始化加载更多功能
            list = new LoadData({
                btn: '#getMoreBtn',
                lists: '#fuliList',
                listType: 'info',
                url: '/fuli/ajax_'+ type +'_list/',
                page: 2,
                template: curTmpl,
                method: 'append',
                loadingAnim: true,
                loadingAnimDom: '.loading-container',
                handleFn: {
                    'id': function ( val ) {
                        return '/' + type + '/' + val;
                    }
                },
                afterRender: function () {
                    $("img").lazyload({
                        effect: "fadeIn",
                        effectspeed: 1500
                    });
                }
            });

            //初始化侧边栏切换功能
            $('#slideTabList').slideTab({
                nodes: {
                    slideTab : '#asidePanelTabs',
                    tabThumb : '#asideTitleTabs',
                    thumbItems : '.panel-title-tab',
                    panelContainer : '.tab-container',
                    panelWrapper : '.tab-panel-wrapper',
                    panelItems : '.tab-panel'
                },
                activeClass: 'tab-active'
            });
        }

    }
    main();

})();